import user from "@/store/modules/user";
import axios from "axios"
const baseUrl = "http://127.0.0.1:5000"
axios.defaults.withCredentials = true;
const userApi = axios.create({
    baseURL: baseUrl,
	headers: {
	    Authorization: `Bearer ${localStorage.getItem('token')}`,
	}
})

userApi.interceptors.response.use(res=>{
	return res
},err=>{
	return err
})
//注册
export const register = (userName,passWord,email,keyCode)=>{
	return userApi({
		url:'/api/register',
		method:'post',
		data:{
			userName,
			email,
			passWord,
			keyCode
		}
	})
}
//登录
export const login = (userName,passWord)=>{
	return userApi({
		url:'/api/login',
		method:'post',
		data:{
			userName,
			passWord
		}
	})
}

export const getinfo = ()=>{
	return userApi({
		url:'/user/getinfo',
		method:'get',
	})
}

//用户token过期 重新获取token
// export const resetToken = ()=>{
// 	return userApi({
// 		url:'/api/resetToken',
// 		method:'get'
// 	})
// }
//更新头像
export const updataImg = (formdata)=>{
	return userApi({
		url:'/user/updataImg',
		method:'post',
		data:formdata
	})
}
//更新主页背景图片
export const updataBgImg = (formdata)=>{
	return userApi({
		url:'/user/updataBgImg',
		method:'post',
		data:formdata
	})
}

export const uploadImg = (formdata,tags)=>{
	let Tags = JSON.stringify(tags)
	return userApi({
		url:`/user/uploadImg?tags=${Tags}`,
		method:'post',
		data:formdata
	})
}

//用户删除自己上传的壁纸
export const deleteUpload = (userId,imgId,imgPath)=>{
	return userApi({
		url:`/user/deleteUpload?imgId=${imgId}&&userId=${userId}&&imgPath=${imgPath}`,
		method:'get'
	})
}

//收藏壁纸
export const collected = (userId,imgDetail)=>{
	return userApi({
		url:'/user/collected',
		method:"post",
		data:{
			userId,
			imgDetail
		}
	})
}

//删除自己收藏的壁纸
export const deleteCollected = (imgId)=>{
	return userApi({
		url:`/user/deleteCollected?imgId=${imgId}`,
		method:'get'
	})
}


//修改密码发送验证码到邮箱
export const sendMail = ()=>{
	return userApi({
		url:`/user/sendKey`,
		method:'post'
	})
}

//更改密码
export const updataPassword = (code,passWord)=>{
	return userApi({
		url:'/user/updataPassword',
		method:'post',
		data:{
			code,
			passWord
		}
	})
}
